package cn.kgc.springcloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 课工场
 * @date 2023/10/12
 * @description
 */
@RestController
@RequestMapping("hystrix")
public class HystrixController {

    @RequestMapping("m1")
    @HystrixCommand(fallbackMethod = "fallbackMethod1")   // 指明通过哪个方法实现快速响应
    public String method1(Integer id){

        System.out.println("===========HystrixController id = "+id+"===============");
        if (id<0){
            throw new RuntimeException("参数异常");
        }

        return "HystrixController ok";
    }

    //  快速响应方法  参数列表 要和method1保持一致
    public String  fallbackMethod1(Integer id){

        return "参数异常，param="+id;
    }


}
